package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.Goods;
import bean.User;
import dao.GoodsViewUser;
import dao.SelectOneGoods;

/**
 * Servlet implementation class DetailServlet
 * 获取商品详细信息，传入页面
 */
public class DetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetailServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String idString = request.getParameter("id");//获取url传来的id值
		int id = Integer.parseInt(idString);//转换成int
		
		User user;
		Goods goods;
		
		goods = SelectOneGoods.getOneGoods(id);//根据id查询到一个商品的信息
		
		int userid = goods.getUserId();//获取到goods表里的userid信息
		user = GoodsViewUser.getGoodsUser(userid);//根据userid查询出出售商品用户的信息
		
		request.setAttribute("user", user);
		request.setAttribute("goods", goods);
		request.getRequestDispatcher("/view/detail.jsp").forward(request,//塞入request，传入显示页面
				response);
		return;
	}

}
